package hmis.pos.Controller;

import hmis.pos.Common.pojo.ApiResponse;
import hmis.pos.Common.vo.CheckIn.OrderDetailAndRoomid;
import hmis.pos.Entity.CheckIn;
import hmis.pos.Entity.OrderDetail;
import hmis.pos.Service.CheckInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("checkin")
@CrossOrigin(origins={"http://localhost:3000"})
public class CheckInController {

    @Autowired
    private CheckInService checkInService;

    @RequestMapping("save")
    @ResponseBody
    public ApiResponse<OrderDetail> save(@RequestBody OrderDetailAndRoomid orderDetailAndRoomid){
        return checkInService.save(orderDetailAndRoomid);
    }

    @RequestMapping("delete")
    @ResponseBody
    public boolean delete(@RequestBody CheckIn checkIn){
        return checkInService.delete(checkIn);
    }

    @RequestMapping("update")
    @ResponseBody
    public CheckIn update(@RequestBody CheckIn checkIn){
        return checkInService.update(checkIn);
    }

    @RequestMapping("findById")
    @ResponseBody
    public CheckIn findById(@RequestParam String id){
        return checkInService.findById(id);
    }

    @RequestMapping("findAll")
    @ResponseBody
    public List<CheckIn> findAll(){
        return checkInService.findAll();
    }

    @RequestMapping("findByRoomid")
    @ResponseBody
    public List<CheckIn> findByRoomid(@RequestParam int roomid){
        return checkInService.findByRoomid(roomid);
    }

    @RequestMapping("checkOut")
    @ResponseBody
    public  ApiResponse<CheckIn> checkOut(@RequestBody CheckIn checkIn){
        return checkInService.checkOut(checkIn);
    }
}
